package com.decheng.controller;

import com.decheng.dto.PaginationDTO;
import com.decheng.pojo.Book;
import com.decheng.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/6/28
 */
@Controller
public class IndexController {

    private final BookService bookService;

    public IndexController(BookService bookService) {
        this.bookService = bookService;
    }

    @GetMapping({"/index", "/"})
    public String index(
            @RequestParam(name = "currentPage", required = false) String currentPage,
            @RequestParam(name = "PageSize", required = false) String pageSize,
            Model model) {

        PaginationDTO<Book> bookList = bookService.findBookList(currentPage, pageSize);
        model.addAttribute("data", bookList);
        return "index";
    }
}
